package ControlLayer;

import java.util.Date;

import ModelLayer.Customers;
import ModelLayer.PaymentTypes;
import ModelLayer.Products;
import ModelLayer.Rent;
import ModelLayer.Rents;
import ModelLayer.Staffs;

public class RentCtr {
	
	private Rent r;
	   
    public RentCtr()
    {
    	Rents.getInstance();
       Products.getInstance();
       Customers.getInstance();
       PaymentTypes.getInstance();
       Staffs.getInstance();
       r = new Rent();
    }

    public void createOrder(String _id, String _productId, String _itemId, String _customerId, String _deliveryTypeId, String _paymentTypeId, String _staffId)
    {
         r.setId(_id);
         Date sysDate = new Date();
         String dateString = sysDate.toString();
         r.setDateCreated(dateString);
         r.addProduct(Products.getProduct(_productId));
         r.setCustomer(Customers.getCustomer(_customerId));
         r.setPaymentType(PaymentTypes.getPaymentType(_paymentTypeId));
         r.setStaff(Staffs.getStaff(_staffId));
         r.setStatus("Created");
         Rents.addRent(r);
    }
    
    public void addProduct(String _productId)
    {
        r.addProduct(Products.getProduct(_productId));
    }
    
    public void deleteProduct(String _productId)
    {
        r.removeProduct(_productId);
    }

    public double calculateTotal()
    {
        r.calculateTotal();
        return r.getTotalPrice();
    }
    
    public void deleteRent(String _rentId)
    {
        Rents.getRent(_rentId).setStatus("Deleted");
    }
    
    public void listAllRents()
    {
        System.out.println("\nRentals:");
        for(int i = 0; i<Rents.getSize(); i++)
        {
            System.out.println("\nID: " + Rents.allRents(i).getId());
            System.out.println("\nTotal Price: " + Rents.allRents(i).getTotalPrice() + "\n");
        }
    }
    
    public void listAllProducts()
    {
        Products.printProducts();
    }
    
    public void listAllCustomers()
    {
        Customers.printCustomers();
    }
    
    public void listAllPaymentTypes()
    {
        PaymentTypes.printPaymentTypes();
    }
    
    public Rent findRent(String _rentId)
    {
        return Rents.getRent(_rentId);
    }
    
    public void listAllStaffs()
    {
        Staffs.listAllStaffs();
    }
}